package com.imay.live.activity;

import android.content.Context;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.imay.base.activity.BaseActivity;
import com.imay.live.adapter.PermissionRuleAdapter;
import com.imay.live.model.PermissionRuleModel;
import com.imay.live.proto.Result;
import com.imay.live.proto.helper.ProtoHttpFactory;
import com.imay.live.proto.helper.ProtoRequestHelper;
import com.imay.live.utils.RecyclerViewUtil;
import com.imay.live.R;

import java.util.List;

import static com.imay.live.proto.ResultCode.CodeSuccess;

/**
 * 我的-设置-查看特权-经验等级
 */
public class PermissionHelpActivity extends BaseRequestActivity {

    public static void start(Context context) {
        Intent starter = new Intent(context, PermissionHelpActivity.class);
        context.startActivity(starter);
    }
    private String loadPerssionRule;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_permission_help;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        setTitle(getString(R.string.permission_rule_title));
           loadData();
    }

    private void loadData(){
        loadPerssionRule = ProtoRequestHelper.task(ProtoHttpFactory.getPermissionRule()).setTag(this.hashCode()).request(this);
    }
    @Override
    public void onRequestSuccess(String command, String data) {
        if (command.equals(loadPerssionRule)){
            Result<List<PermissionRuleModel>> result = JSON.parseObject(data,new TypeReference<Result<List<PermissionRuleModel>>>(){}.getType());
            if (result.result==CodeSuccess){
                RecyclerView recyclerView = $(R.id.rcv_help_permission);
                RecyclerViewUtil.setLinearLayoutManager(this,recyclerView);
                recyclerView.setAdapter(new PermissionRuleAdapter(result.data));
            }
        }

    }

    @Override
    public void onRequestError(String command, int code, String message) {

    }
}
